<?php
namespace app\admin\controller;

class Area extends Base{
	function _initialize(){
		parent::_initialize();
		$this->parent_id    = $this->_get('parent_id', 0);
		$this->up_parent_id = $this->_get('up_parent_id', 0);
		$this->type         = $this->_get('type', 0);

		// 添加修改跳转地址
		$this->_jump_url = url('index', array('parent_id' => $this->parent_id, 'type' => $this->type));
	}
	public function index(){
		
		$where['parent_id'] = $this->parent_id;
		return parent::index('', $where, 'order_id, area_id');
	}

	// 获取地区数据
	public function get_area_list(){
		$where['parent_id'] = $this->_get('parent_id', '', 0);
		$list = model('Area')->where($where)->order('order_id,area_id')->select();
		$data['list'] = $list;

		$this->success('获取数据成功！', '', $data);
	}

	// 删除
	public function delete(){
		$area_id = $this->_get('area_id', '对不起，ID不能为空！');

		if(model('Area')->where(array('parent_id' => $area_id))->count()){
			$this->error('对不起，还有下级内容，无法删除！');
		}else{
			model('Area')->where(array('area_id' => $area_id))->delete();
			$this->success('删除成功！');
		}
	}
}